#include <stdio.h>
#include <stdlib.h>

void serialize(const char *filename, int value) {
    FILE *file = fopen(filename, "wb");
    if(file == NULL) {
        perror("error, can not open file");
        return;
    }

    fwrite(&value, sizeof(int), 1, file);
    fclose(file);
}

int deserialize(const char *filename) {
    FILE *file = fopen(filename, "rb");
    if(file == NULL) {
        perror("error, can not open file");
        return -1;
    }
    int value;
    fread(&value, sizeof(int), 1, file);
    return value;
}

int main() {
    const char *filename = "data.bin";
    int numToSerialize = 16;

    serialize(filename, numToSerialize);
    printf("serialize num:%d\n", numToSerialize);

    int numberBorn = deserialize(filename);
    if(numberBorn != -1) {
        printf("deserialize num:%d\n", numberBorn);
    }
    return 0;
}
